package crypto

import (
	"blueprint-crypto/internal/util"
	"fmt"
	"path/filepath"
	"strings"
)

// 批量解密
func BatchRSA_Decrypt(rootPath string, pempath string, keyword string, newKeyword string) {
	if !util.PathExists(rootPath) {
		panic(rootPath + "路径不存在，请检查")
	}
	if !util.PathExists(pempath) {
		panic(pempath + "文件不存在，请检查")
	}
	secretFiles := util.Getfilepath(rootPath, keyword)

	for _, secretFile := range secretFiles {
		if util.IsFile(secretFile) {
			paths, fileName := filepath.Split(secretFile)
			if strings.Contains(fileName, keyword) {
				newFilename := strings.ReplaceAll(fileName, keyword, newKeyword)
				RSA_Decrypt(secretFile, pempath, paths+newFilename)
				fmt.Println("源文件：", secretFile, " 解密后文件：", paths+newFilename)
			}
		}
	}
}
